<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      list-style: none;
      text-decoration: none;
    }
    .nav{
      width: 100%;
      height: 55px;
      background-color: #ccc;
    }
    .w{
      width: 980px;
      margin: 0 auto;
    }
    li{
      float: left;
      height: 55px;
      line-height: 55px;
      box-sizing: border-box;
     
    }
    a{
      display: block;
      padding:0 20px;
      color:black;
    }
    .active{
      background-color: orange;
    }
    .active a{
      color: white;
    }
  </style>
</head>
<body>
  <div class="nav">
    <div class="w">
      <ul>
        <li class="active"><a href="javastript:;">首页</a></li>
        <li><a href="javastript:;">联系我们</a></li>
        <li><a href="javastript:;">关于我们</a></li>
        <li><a href="javastript:;">课程咨询</a></li>
      </ul>
    </div>
  </div>
  <script>
    var ul =  document.querySelector('ul');
    var lis = ul.children;
    for(var i = 0; i < lis.length; i++){
      lis[i].firstElementChild.onclick = function(){
        for(var j = 0; j < lis.length; j++){
          lis[j].classList.remove('active');
        }
        this.parentNode.classList.add('active')
      }
    }
  </script>
</body>
</html>